package com.kongjs.online.preview.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import java.util.Arrays;

public class OnlinePreviewRequestWrapper extends HttpServletRequestWrapper {
    private static final Logger LOGGER = LoggerFactory.getLogger(OnlinePreviewRequestWrapper.class);
    private final String name;
    private final String[] values;

    public OnlinePreviewRequestWrapper(HttpServletRequest request, String name, String[] values) {
        super(request);
        this.name = name;
        this.values = values;
    }

    @Override
    public String[] getParameterValues(String name) {
        if (name.equals(getName())){
            LOGGER.info(getName()+ Arrays.toString(getValues()));
            return getValues();
        }
        return this.getRequest().getParameterValues(name);
    }
    public String getName() {
        return name;
    }
    public String[] getValues() {
        return values;
    }
}